package com.jcroke.PC32.basetransform;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.LinkedHashMap;

import com.jcroke.DACGraph.Pnode;
import com.jcroke.DACGraph.Signature;
import com.jcroke.PC32.datum.Datum;
import com.jcroke.PC32.exception.TransformerException;

/**
 * Parent class of all transformers.
 * 
 * @author jcroke
 */

public abstract class DefaultTransformer extends Transformer implements
		Functional {

	public void prepare(Pnode pnode) {
		this._pnode = pnode;
		System.out.println("[Prepare] DefaultTransformer runnnig prepare on: "
				+ _pnode.getNodeName());

		super.declareInputFields();

		// Get hash map of pins and types
		ArrayList<Signature> sA = pNode().getOutputSignature();

		for (Signature s : sA) {
			try {
				types.put(
						s.getSourcePin(),
						Class.forName(s.getSourceTypeClass()).getConstructor(
								String.class));
			} catch (Exception e) {
				throw new TransformerException(
						"Could not instantiate input type for: "
								+ s.getSourceTypeClass(), e);
			}
		}
		
		setInput(receive());
	}

	public LinkedHashMap<String, Datum> receive() {
		return (_iBuf);
	}

	public LinkedHashMap<String, Datum> getInput() {
		return input;
	}

	private void setInput(LinkedHashMap<String, Datum> input) {
		this.input = input;
	}

	private Hashtable<String, Constructor<?>> types = new Hashtable<String, Constructor<?>>();
	private LinkedHashMap<String, Datum> input;
}
